package com.example.rockscissorspapergame.utils;

import com.example.rockscissorspapergame.Constants;
import ohos.app.Context;
import ohos.data.distributed.common.KvManagerConfig;
import ohos.data.distributed.common.KvManagerFactory;
import ohos.distributedschedule.interwork.DeviceInfo;
import ohos.distributedschedule.interwork.DeviceManager;

import java.util.List;

/**
 * DeviceUtils
 */
public class DeviceUtils {
    private DeviceUtils() {}

    /**
     * 获取远程设备信息列表
     *
     * @return 远程设备信息列表
     */
    public static List<DeviceInfo> getRemoteDeviceList() {
        return DeviceManager.getDeviceList(DeviceInfo.FLAG_GET_ONLINE_DEVICE);
    }

    /**
     * 获取当前设备 ID
     *
     * @param context 当前上下文
     * @return 设备ID，若获取不到则返回字符串
     */
    public static String getLocalDeviceId(Context context) {
        if (context == null) {
            return Constants.EMPTY_STRING;
        }
        return KvManagerFactory.getInstance()
                .createKvManager(new KvManagerConfig(context)).getLocalDeviceInfo().getId();
    }
}

